< previous page page_280 next page >

Page 280
If strErr <> "" Then
MsgBox strErr, vbExclamation, "Data Error"
mboolError = True
adStatus = adStatusCancel
End If
End If
End Sub
analysis.gifIn this routine, you should check all the controls on the form that must be filled in with correct data. If any of these are in error, create a string value that lists each error in turn. At the end of the routine, you can check this string to see whether its filled in. If so, you can display a message box with this error string to inform the user of the problems with the fields on the form. In addition, you might also want to set a module-level variable called mboolError to a True value to communicate back to the cmdSave_Click() event that an error occurred in the data.
You also need to stop the update to the base table from happening. To do this, you set the adStatus argument to the constant adStatusCancel. This informs the data control to abort the updating of the table.

EXERCISE
Detecting Errors
1. Add a module-level variable called mboolError to the (General) (Declarations) section of the Employee Information form.
2. Change the cmdSave_Click() event to check for this module-level variable:
Private Sub cmdSave_Click()
Dim boolAdding As Boolean

mboolError = False
boolAdding = (datEmployees.Recordset.EditMode = adEditAdd)

datEmployees.Recordset.Update
If Not mboolError Then
If boolAdding Then
datEmployees.Recordset.MoveLast
End If

 
< previous page page_280 next page >

If you like this book, buy it!